package com.atguigu.gmall.mapper;

import com.atguigu.gmall.bean.KeywordStats;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface KeywordStatsMapper {

    @Select("select \n" +
            "       keyword,\n" +
            "       sum(keyword_stats_2021.ct * multiIf(\n" +
            "           source ='SEARCH',10,\n" +
            "           source ='ORDER',5,\n" +
            "           source ='CART',2,\n" +
            "           source ='CLICK',1,0\n" +
            "           ))  ct\n" +
            "       from keyword_stats_2021\n" +
            "where toYYYYMMDD(stt) = #{date}\n" +
            "group by keyword\n" +
            "order by sum(keyword_stats_2021.ct) \n" +
            "limit #{limit};")
    public List<KeywordStats> selectKeywordsStats(@Param("date") int date, @Param("limit") int limit);



}
